# coding: utf-8
import sqlite3
import uuid

db_path = 'db.sqlite3'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

print("Current users:")
cursor.execute("SELECT phone FROM Server_user")
users = cursor.fetchall()
for u in users:
    print("  Phone:", u[0])

# Add user 13088888888
phone = '13088888888'
row = cursor.execute("SELECT id, username, password, head_portrait FROM Server_user WHERE phone = ?", (phone,)).fetchone()
if row:
    print("\nPhone %s already exists" % phone)
    # 更新为开发测试友好的数据
    default_portrait = 'users/default/user_portrait.png'
    default_password = '123456'
    cursor.execute(
        "UPDATE Server_user SET username = ?, password = ?, head_portrait = ? WHERE phone = ?",
        ('testuser', default_password, default_portrait, phone)
    )
    conn.commit()
    print("Updated existing user to default testing values.")
else:
    print("\nAdding phone %s..." % phone)
    user_id = str(uuid.uuid4())
    # 使用与后端逻辑一致的默认头像路径与明文密码（开发环境）
    default_portrait = 'users/default/user_portrait.png'
    default_password = '123456'
    cursor.execute(
        """
        INSERT INTO Server_user (id, username, password, phone, head_portrait, is_admin, money)
        VALUES (?, ?, ?, ?, ?, ?, ?)
        """,
        (user_id, 'testuser', default_password, phone, default_portrait, 0, 1000.0)
    )
    conn.commit()
    print("SUCCESS! User created.")

conn.close()
print("\nDone! You can now login with phone: %s" % phone)

